# coding: utf-8

from util import udpSocketClient, logging, sysEncode, BUF_SIZE

ADDR = ('127.0.0.1', 10021)       #服务器端地址

def saveData(sock, fileName):
	count = 0
	while True:
		if count == 0:
			sock.sendto('hello', ADDR)

		recvdata, addr = sock.recvfrom(BUF_SIZE)
		if recvdata == 'end':
			break
		else:
			with open(fileName, 'ab') as f:
				f.write(recvdata)
		count += 1
		print count
	
def main():
	sock = udpSocketClient()
	
	saveData(sock, '01.jpg')

	sock.close()

if __name__ == '__main__':
	main()